import XForm from './XFrom'
import XTable from './XTable'

import {
  COMPONENT_TYPE,
  CUSTOM_EVENT_TYPE,
  SLOT_WRAPPER_SUFFIX,
  SLOT_PREFIX,
  DESIGN_COMPONENT_SUFFIX,
  RENDER_OPTIONS
} from './libs/constants'

import XRenderComponentMixin from './libs/XRenderMixins/XRenderComponentMixin'
import XRenderDateMixin from './libs/XRenderMixins/XRenderDateMixin'
import XRenderDesignMixin from './libs/XRenderMixins/XRenderDesignMixin'
import XRenderExtendSlotMixin from './libs/XRenderMixins/XRenderExtendSlotMixin'
// 滚动条
import PerfectScrollbar from 'vue2-perfect-scrollbar'
import 'vue2-perfect-scrollbar/dist/vue2-perfect-scrollbar.css'
// vuedraggable
import VueDraggable from 'vuedraggable'
import BaseComponents from './libs/components/index'
import BaseLayouts from './libs/layouts/index'
// 需要注册的组件列表
const registerComponents = [
  XForm,
  XTable
]
// 导出的给用户使用的组件信息
const renderComponents = []

// 添加基础组件
const addBaseComponent = function() {
  for (const info of BaseComponents) {
    const { component, baseInfo } = info
    if (component) {
      registerComponents.push(component)
    }
    if (baseInfo) {
      renderComponents.push(info)
    }
  }
}
// 添加基础布局
const addBaseLayouts = function() {
  for (const info of BaseLayouts) {
    const { component, baseInfo, design } = info
    if (component) {
      registerComponents.push(component)
    }
    if (design) {
      registerComponents.push(design)
    }
    if (baseInfo) {
      renderComponents.push(info)
    }
  }
}

const install = (Vue, opts = {}) => {
  addBaseComponent()
  addBaseLayouts()
  registerComponents.forEach(component => Vue.component(component.name, component))
  // 设置参数
  Vue.prototype.$XRenderOptions = Object.assign({ isDebug: true }, opts)
  // 组件信息
  Vue.prototype.$XRenderComponentInfo = renderComponents
  // 滚动条
  Vue.use(PerfectScrollbar)
  // VueDraggable
  Vue.component('VueDraggable', VueDraggable)
}

export default {
  install,
  COMPONENT_TYPE,
  CUSTOM_EVENT_TYPE,
  SLOT_WRAPPER_SUFFIX,
  SLOT_PREFIX,
  DESIGN_COMPONENT_SUFFIX,
  RENDER_OPTIONS
}

export {
  install,
  COMPONENT_TYPE,
  CUSTOM_EVENT_TYPE,
  SLOT_WRAPPER_SUFFIX,
  SLOT_PREFIX,
  DESIGN_COMPONENT_SUFFIX,
  RENDER_OPTIONS,
  XRenderComponentMixin,
  XRenderExtendSlotMixin,
  XRenderDesignMixin,
  XRenderDateMixin
}
